<template>
  <ul class="levelList-container">
    <li v-for="(item, i) in list" :key="i">
      <span @click="handleClick(item)" :class="{ active: item.isSelect }">{{
        item.name
      }}</span>
      <span class="aside" :class="{ active: item.isSelect }">{{
        item.aside
      }}</span>
      <LevelList :list="item.children" @select="handleClick" />
    </li>
  </ul>
</template>

<script>
export default {
  name: "LevelList", //组件递归命名
  props: {
    // [ {name:"xxx", isSelect:true, children:[ {name:"yyy", isSelect: false} ] } ]
    list: {
      type: Array,
      default: () => [], //默认数组的写法
    },
  },
  methods: {
    handleClick(item) {
      //单击的时候要把点击的哪个元素扔给父级处理
      this.$emit("select", item);
    },
  },
};
</script>

<style lang="less" scoped>
@import "~@/styles/var.less";
.levelList-container {
  list-style: none;
  padding: 0;
  margin: 0;
  li {
    min-height: 40px;
    line-height: 40px;
    margin-left: 1em;
    cursor: pointer;
  }

  .active {
    color: @danger;
    font-weight: bold;
  }
}
.aside {
  font-size: 12px;
  margin-left: 1em;
  color: @gray;
}
</style>